package event;

public class Girl extends Thread{
	private EmotionListener listener;
	private String name;
	private int day;
	public Girl(String lover){
		this.name = lover;
	}
	public String getLover(){
		return name;
	}
	public void setEmotionListener(EmotionListener l) throws HeartOccupiedException{
		if(listener!=null){
			System.out.println("Do not you know I have had a lover");
			throw new HeartOccupiedException("My heart is full");
		}
		System.out.println("Finally I have another half");
		listener = l;
	}
	public void removeEmotionListener(EmotionListener l){
		if(listener==l){
			System.out.println("I can't live without you");
			listener=null;
		}
	}
	public void run(){
		while(true){
			try {
				Thread.sleep(1000);
				day++;
				fire();
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}
	private void fire(){
		EmotionEvent evt = new EmotionEvent(this);
		if(listener==null){
			System.out.println("Being a single is lone");
			return;
		}
		if(day%2==0)
			listener.happy(evt);
		else
			listener.sad(evt);
	}
}
